<?php
/**
 * Extend Zend_Application_Resource_Translate
 * Auto select translate file by locale
 * 
 * @copyright  Copyright (c) 2011 Ricky Feng (http://code.google.com/p/rphp4zf)
 * @license    New BSD License
 */

class Mediad2_Application_Resource_Auth extends Zend_Application_Resource_ResourceAbstract
{
    public function init()
    {
    	$options = $this->getOptions();
    	
    	//判断是否设置options中的namespace/member/registryName，如果没有则增加默认值
    	if (!isset($options['Mediad2']['namespace'])) {
    		$options['Mediad2']['namespace'] = 'Mediad2';
    	}
    	if (!isset($options['Mediad2']['user'])) {
    		$options['Mediad2']['member'] = 'User';
    	}
    	if (!isset($options['registryName'])) {
    		$options['registryName'] = 'auth';
    	}

        // Save a reference to the Singleton instance of Zend_Auth
        $auth = Zend_Auth::getInstance();
        
        $auth->setStorage(new Zend_Auth_Storage_Session($options['Mediad2']['namespace'],$options['Mediad2']['member']));
        
        //保存进注册表
        Zend_Registry::set($options['registryName'], $auth);
        
        return $auth;

    }
}

